package com.kfm.base.thread.day01;

public class Demo11 {

    public static void main(String[] args) {
        R r = new R();
        Thread t1 = new Thread(r);
        Thread t2 = new Thread(r);
        Thread t3 = new Thread(r);

        t1.start();
        t2.start();
        t3.start();

    }


}

class R implements Runnable {

    @Override
    public void run() {
        while (true){
            test();
        }
    }

    public synchronized void test(){
        for (int i = 0; i < 10; i++){
            System.out.println(i);
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }
}
